package com.dragon.blog.gateway.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

import java.util.Collections;

/**
 * @INFO:
 * @AUTHOR NAIZUI
 * @CLASSNAME BlogCorsConfiguration.java
 * @CREATETIME 2021-09-28 17:53
 */
@Configuration
public class BlogCorsConfiguration {

    @Bean
    public CorsWebFilter corsWebFilter() {
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        //1,容许任何来源
        corsConfiguration.setAllowedOriginPatterns(Collections.singletonList("*"));
        //2,容许任何请求头
        corsConfiguration.addAllowedHeader(CorsConfiguration.ALL);
        //3,容许任何方法
        corsConfiguration.addAllowedMethod(CorsConfiguration.ALL);
        //4,容许凭证
        corsConfiguration.setAllowCredentials(true);

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", corsConfiguration);
        return new CorsWebFilter(source);
    }




}
